#pragma once
//本Task.hpp 用来派发任务，
//我们可以设计各种类型的任务，来让生产者传到阻塞队列中，
//再让消费者在其中获取

//简单设计一个 “自动计算器”//
enum ReErrno
{
    Correct,
    Zero,
    Unknown
};
template<class T>
class Task
{
public:
    Task()
    {}
    Task(T data1, T data2, char rule)  
        : _data1(data1)
        , _data2(data2)
        , _rule(rule)
        , _result(0)
        , _rerrno(Correct)
    {}
    ~Task()
    {}
    void Run()
    {
        switch (_rule)
        {
            case '+':
                _result = _data1 + _data2;
                break;
            case '-':
                _result = _data1 - _data2;
                break;
            case '*':
                _result = _data1 * _data2;
                break;
            case '/':
            {
                if(_data2 == 0)
                {
                    _rerrno = Zero;
                }
                _result = _data1 / _data2;
            }
                break;
            case '%':
            {
                if(_data2 == 0)
                {
                    _rerrno = Zero;
                }
                _result = _data1 % _data2;
            }
                break;
            default:
                _rerrno = Unknown;
                break;
        }
    }
    void operator*(Task<T> task)
    {
        _data1 = task._data1;
        _data2 = task._data2;
        _rule = task._rule;
        _result = task._result;
        _rerrno = task._rerrno;
    }
    
    void TaskPrint()
    {
        // printf("%d %c %d = ?\n", _data1, _rule, _data2);
        std::cout << _data1 << " " << _rule << " " << _data2 
        << " " << "= ?" << std::endl;
    }

    void ResultPrint()
    {
        // printf("%d %c %d = %d [%s]\n", _data1, _rule, _data2, 
                                    //    _result, To_string().c_str());
         std::cout << _data1 << " " << _rule << " " << _data2 
        << " " << "= " << _result << "[" << To_string() << "]" << std::endl;
    }

    std::string To_string()
    {
        switch(_rerrno)
        {
            case 0:
                return "Correct";
            case 1:
                return "Zero";
            default:
                return "Unknown";
        }
    }
private:
    T _data1;
    T _data2;
    char _rule;
    T _result;
    int _rerrno;
};